package com.lmqb.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lmqb.bean.SysMenu;
import com.lmqb.bean.SysUser;
import com.lmqb.bean.SysUserOperationLog;
import com.lmqb.dao.SysMenuMapper;
import com.lmqb.dao.SysUserOperationLogMapper;
import com.lmqb.service.SysMenuService;
import com.lmqb.util.StrUtil;

@Service("sysMenuService")
public class SysMenuServiceImpl implements SysMenuService{

	@Autowired
	private SysMenuMapper sysMenuDao;
	
	@Autowired
	private SysUserOperationLogMapper sysUserLogDao;
	
	/*
	 * 权限管理列表
	 * */
	public List<SysMenu> selectAll(SysMenu sysMenu) {
		List<SysMenu> list=sysMenuDao.selectAll(sysMenu);
		return list;
	}

	//@Override
	public void insert(SysMenu sysMenu,SysUser sysUser) {
		sysMenuDao.insert(sysMenu);
		//添加管理员操作记录
		SysUserOperationLog log=new SysUserOperationLog();
		log.setAddTime(StrUtil.timeToInt(new Date()));
		log.setLoginName(sysUser.getLoginName());
		log.setObjectId(sysMenu.getMenuId()+"");
		log.setOperationCate((byte)5);
		log.setOperationContent("添加权限。"+sysMenu.toString());
		log.setRealName(sysUser.getRealName());
		log.setUserId(sysUser.getUserId());
		log.setTableName("sys_menu");
		sysUserLogDao.insert(log);
	}

	//@Override
	public void update(SysMenu sysMenu) {
		sysMenuDao.updateByPrimaryKeySelective(sysMenu);
		
	}

	//@Override
	public SysMenu selectById(Integer menuId) {
		SysMenu sysMenu=sysMenuDao.selectByPrimaryKey(menuId);
		return sysMenu;
	}

}
